// Global variables 
// **************** 
//folder.desc	--目录名称
//folder.fid	--代码

indexOfEntries = new Array 
nEntries = 0 
doc = document 
browserVersion = 0 
selectedFolder=0
curfoldid=0


//创建文件夹的类。
function Folder(folderDescription, hreference,name) //constructor 
{ 
	this.desc = folderDescription 
	this.id = -1 
	this.navObj = 0
	this.nodeImg = 0
    this.fid=name
    
	//dynamic data 
	this.isOpen = true 
	this.iconSrc = imageminus
	this.children = new Array 
	this.nChildren = 0
	this.parentid=0				//父项文件夹
	this.ordernum=0				//文件夹的序号 
 
	//methods 
	this.initialize = initializeFolder 
	this.setState = setStateFolder 
	this.addChild = addChild 
	this.createIndex = createEntryIndex 
	this.hide = hideFolder 
	this.display = display
	this.renderOb = drawFolder 
	this.totalHeight = totalHeight 
	this.subEntries = folderSubEntries 
} 


//设置文件夹的状态 
function setStateFolder(isOpen) 
{ 
	var subEntries 
	var totalHeight 
	var fIt = 0 
	var i=0 
 
	if (isOpen == this.isOpen) return 
 
	if (browserVersion == 2) 
	{ 
		totalHeight = 0 
		for (i=0; i < this.nChildren; i++) 
			totalHeight = totalHeight + this.children[i].navObj.clip.height 
		subEntries = this.subEntries() 
		if (this.isOpen) totalHeight = 0 - totalHeight 
		for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) 
			indexOfEntries[fIt].navObj.moveBy(0, totalHeight) 
	}
	this.isOpen = isOpen 
	propagateChangesInState(this) 
} 


//改变文件夹的图表 
function propagateChangesInState(folder) 
{   
	var i=0 
	//var name1=String(clickedFolder.fid)

	if (folder.ordernum<folder.parentid.nChildren)				//不是最后一级
	{
		if (folder.nChildren!=0)									//有子目录
		{
			if (folder.isOpen)										//文件夹打开
			{
				folder.nodeImg.src =imageminus_m
			}
			else
			{
				folder.nodeImg.src =imageplus_m
			}
		}		
		else
		{
			//alert (name1)
			folder.nodeImg.src =imageunique_m
		}
	}
	else
	{
		if (folder.nChildren!=0)									//有子目录
		{
			if (folder.isOpen)										//文件夹没有打开
			{
				folder.nodeImg.src =imageminus_n
			}
			else
			{
				folder.nodeImg.src =imageplus_n
			}
		}		
		else
		{
			folder.nodeImg.src =imageunique_n
		}
	}
	
	if (folder.isOpen) 
	{ 
		for (i=0; i<folder.nChildren; i++) folder.children[i].display() 
	} 
	else 
	{ 
		for (i=0; i<folder.nChildren; i++) folder.children[i].hide() 
	}
} 

//隐藏文件夹
function hideFolder() 
{ 
  if (browserVersion == 1) { 
    if (this.navObj.style.display == "none") 
      return 
    this.navObj.style.display = "none" 
  } else { 
    if (this.navObj.visibility == "hiden") 
      return 
    this.navObj.visibility = "hiden" 
  } 
   
  this.setState(0) 
} 

 
//初始化文件夹
function initializeFolder(level, leftSide,mark) 
{ 
	var j=0 
	var i=0 
	var numberOfFolders 
	var numberOfDocs 
	var nc 

	nc = this.nChildren 
 	this.createIndex() 
	if (level>2)
	{
		if (mark==1) 
			leftSide = leftSide + "<img src=" + imageblank_m + "  border=0>"
		else
			leftSide = leftSide + "<img src=" + imageblank_n + "  border=0>"
		this.renderOb(leftSide)
	}
	else 
	{
		this.renderOb("") 
	}
	
	if (nc > 0)
	{ 
		level = level + 1 
		for (i=0 ; i < this.nChildren; i++)
		{ 
			if (this.ordernum<this.parentid.nChildren)			//父项不是末级
				this.children[i].initialize(level, leftSide,1) 	
			else
				this.children[i].initialize(level, leftSide,0) 	
		} 
	}
} 

//输出文件夹 
function drawFolder(leftSide) 
{ 
	if (browserVersion == 2)
	{ 
		if (!doc.yPos) doc.yPos=8 
		doc.write("<layer id='folder" + this.id + "' top=" + doc.yPos + " visibility=hiden>") 
	} 
 
	doc.write("<table ") 
	if (browserVersion == 1)
	{ 
		doc.write("id='folder" + this.id + "' style='position:block;'")
	}
	
	doc.write("cellspacing=0 cellpadding=0>")
	doc.write("<tr onmouseover=this.style.cursor='hand' onclick='javascript:clickFolder("+this.id+")'><td nowrap>")
	doc.write(leftSide)
	 
	if (this.id>0) 
	{
	var clickedFolder = indexOfEntries[this.id] 
	var DataCode=String(clickedFolder.fid)
	var tempnum=this.id+1
	doc.write("<span style='font-size:9pt;font-color=0000ff;text-decoration:none'>")

	if (this.id==1)
		{
			doc.write("<input type=hidden id=typeroot name='nodeIcon" + this.id + "' border=0 value="+DataCode+"><img id=stat1 src="+imageopen+" border=0></span>")
		}
	else
		{
			doc.write("<img id=type"+this.id+" name='nodeIcon" + this.id + "' src=" + imageplus +"  border=0></span><img id=stat"+this.id+" src="+imageclose+" border=0>")
		}
		
		doc.write("</td><td valign=middle nowrap>")
		
		doc.write("<span style='font-size:9pt;font-color=0000ff;'>[" + this.desc.split("-")[0] + "]</span>") 
		
		doc.write("</td><td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;</td></tr>")
		}
 		doc.writeln("</table>") 

		if (browserVersion == 2) doc.write("</layer>")
		if (browserVersion == 1)
		{ 
			this.navObj = doc.all["folder"+this.id] 
			if (this.id>0) 
			{
				this.nodeImg = doc.all["nodeIcon"+this.id] 
				this.nodeImg.src = imageminus
			}
		}
		else if (browserVersion == 2)
		{
			this.navObj = doc.layers["folder"+this.id] 
			if (this.id>0) 
			{
				this.nodeImg = this.navObj.document.images["nodeIcon"+this.id] 
				this.nodeImg.src = imageminus
			}
			doc.yPos=doc.yPos+this.navObj.clip.height 
		}

	//} 
} 

//增加子节点
function addChild(childNode) 
{ 
	this.children[this.nChildren] = childNode 
	childNode.parentid=this
	childNode.ordernum=this.nChildren+1
	this.nChildren++ 
	return childNode 
} 
 
 
function folderSubEntries() 
{ 
	var i = 0 
	var se = this.nChildren 
 
	for (i=0; i < this.nChildren; i++){ 
		if (this.children[i].children) //is a folder 
			se = se + this.children[i].subEntries() 
	}
	return se 
} 

// Methods common to both objects (pseudo-inheritance) 
// ******************************************************** 
 
function display() 
{ 
	if (this.id!=0)
	{
	if (browserVersion == 1) 
		this.navObj.style.display = "block" 
	else 
		this.navObj.visibility = "show" 
	}
}  
 
function createEntryIndex() 
{ 
	this.id = nEntries 
	indexOfEntries[nEntries] = this 
	nEntries++ 
} 
 
// total height of subEntries open 
function totalHeight() //used with browserVersion == 2 
{ 
	var h = this.navObj.clip.height 
	var i = 0 
 
	if (this.isOpen) //is a folder and _is_ open 
		for (i=0 ; i < this.nChildren; i++)
	h = h + this.children[i].totalHeight() 

	return h 
} 
 
 
// Events 
// ********************************************************* 
 
function clickOnFolder(folderId) 
{ 
	var clicked = indexOfEntries[folderId] 
 
	if (!clicked.isOpen) clickFolder(folderId) 
	return
 
	if (clicked.isSelected) return 
	
} 
 
function clickFolder(folderId) 
{ 
	var clickedFolder = 0 
	var state = 0 
	var tmpid=curfoldid
	if (folderId==0) return
	
	
	if ((curfoldid!=0)&&(folder.parentID!=curfoldid))
		{//alert(this.parentID)
			doc.all("stat"+curfoldid).src=imageclose
		}
	else
		{
			doc.all("stat"+folderId).src=imageopen	
		}
	curfoldid=folderId

	clickedFolder = indexOfEntries[folderId] 
	state = clickedFolder.isOpen 
 
	clickedFolder.setState(!state)					 //open<->close
	var name1=String(clickedFolder.fid)
	var s_flag=(String(clickedFolder.desc))
	var name2=name1.substr(3,name1.length-1)
	document.all("folderid").value=name1
	document.all("folderstate").value=!state
	var name3="stat"+folderId
	if ((folderId!=0)&&(state==0))
		{
			document.all(name3).src=imageopen
		}
	if ((folderId!=0)&&(state!=0))
		{
			document.all(name3).src=imageclose
		}
	if (!state)
		//alert (doc)
		myfolderClick(name1,!state,s_flag)
}

function initializeDocument() 
{ 
	if (doc.all)
		browserVersion = 1 //IE4 
	else 
		if (doc.layers) browserVersion = 2 //NS4 
	else 
		browserVersion = 0 //other 
 
	foldersTree.initialize(0, "")
	foldersTree.display()

	if (browserVersion > 0) { 
		doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+">&nbsp;</layer>") 
		// close the whole tree 
		 clickFolder(1) 
		// open the root folder 
		 clickFolder(1)
	}
	 
} 
 
// Auxiliary Functions for Folder-Treee backward compatibility 
// ********************************************************* 
 
function gFld(description, hreference,name) 
{ 
	folder = new Folder(description, hreference,name) 
	return folder 
	
} 
 
 ///////////////////////////////////////////////////
function insFld(parentFolder, childFolder) 
{ 
	return parentFolder.addChild(childFolder) 
} 

